PredictiveCacheController

class PredictiveCacheController @JvmOverloads() constructor(predictiveCacheLocationOptions: PredictiveCacheLocationOptions, predictiveCacheControllerErrorHandler: PredictiveCacheControllerErrorHandler?)

Predictive caching is a system that downloads necessary visual map and guidance data resources along the route upfront, before they are needed, in an attempt to provide a smooth experience even when connectivity is lost while using the app.

Once instantiated, the controller will immediately start caching guidance data.

In order to start caching map data, provide an instance via createMapControllers. To specify sources to cache, pass a list of id's via createMapControllers. Source id's should look like "mapbox://mapbox.satellite", "mapbox://mapbox.mapbox-terrain-v2". The system only supports source hosted on Mapbox Services which URL starts with "mapbox://". If no ids are passed all available style sources will be cached.

The controller as well as MapboxNavigation instance it's holding can have a different lifecycle than the MapboxMap instance, so make sure to call removeMapControllers whenever the MapView is destroyed to avoid leaking references or downloading unnecessary resources. When the map instance is recreated, set it back with createMapControllers.

The map instance has to be configured with the same TileStore instance that was provided to RoutingTilesOptions.tileStore. You need to call TileStore.create with a path and pass it to ResourceOptions.tileStore or use the Maps SDK's tile store path XML attribute.

Call onDestroy to cleanup all map and navigation state related references. This can be called when navigation session finishes and predictive caching is not needed anymore.

  • When migrating please ensure you have cleaned up old navigation tiles cache folder to reclaim disk space. Navigation SDK 2.0 caches navigation tiles in a default folder under APP_FOLDER/mbx_nav/tiles/api.mapbox.com. Previous versions of Nav SDK used to cache tiles under a default folder APP_FOLDER/Offline/api.mapbox.com/$tilesVersion/tiles. Old cache is not compatible with a new version of SDK 2.0. It makes sense to delete any folders used previously for caching including a default one.

  • OnboardRouterOptions enabled you to specify a path where nav-tiles will be saved and if a custom directory was used, it should be cleared as well.

Parameters

predictiveCacheLocationOptions

PredictiveCacheLocationOptions location configuration for navigation predictive caching

predictiveCacheControllerErrorHandler

Constructors

PredictiveCacheController
Link copied to clipboard
fun PredictiveCacheController(predictiveCacheLocationOptions: PredictiveCacheLocationOptions = PredictiveCacheLocationOptions.Builder().build(), predictiveCacheControllerErrorHandler: PredictiveCacheControllerErrorHandler? = null)
PredictiveCacheLocationOptions location configuration for navigation predictive caching

Functions

createMapControllers
Link copied to clipboard
fun createMapControllers(map: MapboxMap, sourceIdsToCache: List<String> = emptyList())
Create cache controllers for a map instance.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
open fun hashCode(): Int
onDestroy
Link copied to clipboard
fun onDestroy()
Cleans up all map and navigation state related references.
removeMapControllers
Link copied to clipboard
fun removeMapControllers(map: MapboxMap)
Remove the map instance.
toString
Link copied to clipboard
open fun toString(): String